package net.dgg.zz.production.abnormal.controller;

import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.util.datatable.DataTableUtils;
import net.dgg.iboss.base.util.datatable.domain.DataTableRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author 赵有文
 * @despriction
 * @create 2018/5/29 0029 上午 11:20
 **/
public abstract class ZzBaseController extends DggBaseController {
    /**
     * 生成sql查询的分页、排序参数 limit start sortCol sortType
     *
     * @param paras
     * @param request
     * @return
     */
    protected DataTableRequest generatePatameter(Map paras, HttpServletRequest request) {
        DataTableRequest r = DataTableUtils.getParam(request);
        //分页参数
        paras.put("start", (r.getPage() - 1) * r.getLength());
        paras.put("limit", r.getLength());
        //排序列 排序方式
        String orderCol = null, sortType = null;

        if (null != r.getOrder() && r.getOrder().size() > 0) {
            int orderColIndex = r.getOrder().get(0).getColumn();
            orderCol = r.getColumns().get(orderColIndex).getData();
            sortType = r.getOrder().get(0).getDir();
        } else {
            orderCol = "createTime";
            sortType = "desc";
        }
        paras.put("sortCol", orderCol);
        paras.put("sortType", sortType);

        return r;
    }

}
